#pragma once
#include "oci.h"
#include "ErrorCheck.h"
#include <vector>
#include <crtdbg.h>
#include "DBTOOLS.h"

using namespace std;
//_declspec(dllexport)
class  FMDBApplication
{
public://methods
	FMDBApplication(void);
	~FMDBApplication(void);
	
	//DB operation
	void InitOCIEvn();
	void ReleaseOCIEnv();

	//session operation
	OCISvcCtx *CreateSession(sb4 iStatementCache=-1);
	OCISvcCtx *CreateSession(TCHAR AttriValue[][64],ub4 *AttriCode,short AttriNumber);
	OCISvcCtx *CreateSession(TCHAR AttriValue[][64],ub4 *AttriCode,short AttriNumber,sb4 iStatementCache);

	void ReleaseSession(OCISvcCtx *pSession);

public://properties
	//connect string
	TCHAR *GetConnectionString(){return m_pConString;}
	void SetConnectionString(TCHAR *val){DBTOOLS::CopyPropertyValue(&m_pConString,val);}

	//user name
	TCHAR *GetUserName(){return m_pUserName;}
	void SetUserName(TCHAR *val){DBTOOLS::CopyPropertyValue(&m_pUserName,val);}

	//password,read only
	void SetPassword(TCHAR *val){DBTOOLS::CopyPropertyValue(&m_pPassword,val);}

	//statement cache size
	ub4 GetStatementCacheSize(){return m_stmt_CacheSize;}
	void SetStatementCacheSize(ub4 val){m_stmt_CacheSize=val;}

	//database status
	bool GetDBAvailable(){return m_bIsDBAvailable;}

	//create a new oci error handler, release by caller
	OCIError *GetOCIErrorHandle();
	//oci environment,read only
	OCIEnv *GetOCIEnv(){return m_pEnv;}

private:
private:
	TCHAR* m_pConString;//connection string

	//OCI variables
	OCIEnv *m_pEnv;			//oci environment handle
	OCIError *m_pErr;		//oci error handle, note:this error handle is only used by DBApplication object. 
	OCIAuthInfo *m_pAuth;	//oci Authentication handle
	OCISPool *m_pSpool;		//oci session pool

	//session pool variables
	TCHAR* m_pPoolName;		//session pool name
	ub4 m_PoolNameLen;		//length of session pool name,bytes 
	ub4 m_min_pool;			//minimal sessions in session pool
	ub4 m_max_pool;			//maximum sessions in session pool
	ub4 m_increment_pool;	//the number to increment session pool by
	
	//authentication
	TCHAR* m_pUserName;
	TCHAR* m_pPassword;//note: password should be encrypted in RDM.ini. only get plan text when it's using

	//statement cache size
	ub4 m_stmt_CacheSize;

	//others
	bool m_bIsDBAvailable;//indicate if the database is opened and available

};

